/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package devbureau.fstore.common.load.impl;

import devbureau.fstore.common.CustomerData;
import devbureau.fstore.common.OrderData;
import devbureau.fstore.common.load.FileWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

/**
 *
 * @author Vladimir
 */
public class WordFileWriter implements FileWriter {
    private String fileFormat = null;

    public WordFileWriter(String fileFormat) {
        this.fileFormat = fileFormat;
    }

    public String writeOrder(OrderData order, CustomerData customer) throws Exception {
        String fileName = order.getCustomerId() + "_" + order.getId() + fileFormat;
        
        // POI apparently can't create a document from scratch,
        // so we need an existing empty dummy document
        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("empty.doc"));
        HWPFDocument document = new HWPFDocument(fs);

        FileOutputStream out = new FileOutputStream(fileName);
        document.write(out);
        out.close();

        return fileName;
    }

}
